<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let arr1 = [1,2,3,4,5,4,3,2,1]
        let arr2 = [4,5,6,5,6]
        //1.数组去重
        let res1 = [...new Set(arr1)]
        console.log(res1)
        //2.求数组交集
        let set1 = new Set(arr1)
        let res2 = [...new Set(arr2)].filter(item=>set1.has(item))
        console.log(res2)
        //3.求数组并集
        let union = [...new Set([...arr1, ...arr2])]
        console.log(union)
        //4.求数组差集arr2-arr1 (交集的逆运算)
        let diff =  [...new Set(arr2)].filter(item=>!set1.has(item))
        console.log(diff)
    </script>
</body>
</html>